home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
frasr182.zip
/
MISCFRAC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-13
|
59KB
|
2,169 lines
/*
Miscellaneous fractal-specific code (formerly in CALCFRAC.C)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <float.h>
#ifndef XFRACT
#include <dos.h>
#endif
#include <limits.h>
#include "fractint.h"
#include "fractype.h"
#include "mpmath.h"
#include "targa_lc.h"
#include "prototyp.h"
/* routines in this module */
static void set_Plasma_palette(void);
static U16 _fastcall adjust(int xa,int ya,int x,int y,int xb,int yb);
static void _fastcall subDivide(int x1,int y1,int x2,int y2);
static int _fastcall new_subD (int x1,int y1,int x2,int y2, int recur);
static void verhulst(void);
static void Bif_Period_Init(void);
static int _fastcall Bif_Periodic(int);
static void set_Cellular_palette(void);
U16 (_fastcall *getpix)(int,int) = (U16(_fastcall *)(int,int))getcolor;
extern int resuming;
extern char stdcalcmode;
extern int color, oldcolor, row, col, passes;
extern int ixstart, ixstop, iystart, iystop;
extern _CMPLX init,tmp,old,new,saved;
extern _CMPLX parm,parm2;
extern double far *dx0, far *dy0;
extern double far *dx1, far *dy1;
extern long far *lx0, far *ly0;
extern long far *lx1, far *ly1;
extern long delx, dely;
extern double deltaX, deltaY;
extern int sxoffs, syoffs, sxdots, sydots;
extern int xdots, ydots;
extern int maxit, inside, colors, andcolor, dotmode;
extern double param[];
extern int rflag, rseed;
extern int pot16bit, potflag;
extern int diskvideo;
extern int bitshift;
extern long fudge;
extern int show_orbit;
extern int periodicitycheck, integerfractal;
extern _LCMPLX linit;
extern _LCMPLX ltmp;
extern _LCMPLX lold,lnew,lparm,lparm2;
extern long ltempsqrx,ltempsqry;
extern double tempsqrx,tempsqry;
extern int overflow;
extern int kbdcount, max_kbdcount;
extern int reset_periodicity;
extern int calc_status;
extern int iterations, invert;
extern int save_release;
extern int LogFlag;
extern int (calctype());
extern int realcolor;
extern int nxtscreenflag;
extern double magnitude, rqlim, rqlim2, rqlim_save;
extern long lmagnitud, llimit, llimit2, lclosenuff, l16triglim;
extern int orbit_color, orbit_ptr, showdot;
extern int debugflag;
#ifndef XFRACT
extern char dstack[4096];
extern char boxy[4096];
#else
BYTE dstack[4096];
#endif
typedef void (_fastcall *PLOT)(int,int,int);
/***************** standalone engine for "test" ********************/
int test()
{
int startrow,startpass,numpasses;
startrow = startpass = 0;
if (resuming)
{
start_resume();
get_resume(sizeof(int),&startrow,sizeof(int),&startpass,0);
end_resume();
}
if(teststart()) /* assume it was stand-alone, doesn't want passes logic */
return(0);
numpasses = (stdcalcmode == '1') ? 0 : 1;
for (passes=startpass; passes <= numpasses ; passes++)
{
for (row = startrow; row <= iystop; row=row+1+numpasses)
{
register int col;
for (col = 0; col <= ixstop; col++) /* look at each point on screen */
{
register color;
init.y = dy0[row]+dy1[col];
init.x = dx0[col]+dx1[row];
if(check_key())
{
testend();
alloc_resume(20,1);
put_resume(sizeof(int),&row,sizeof(int),&passes,0);
return(-1);
}
color = testpt(init.x,init.y,parm.x,parm.y,maxit,inside);
if (color >= colors) /* avoid trouble if color is 0 */
if (colors < 16)
color &= andcolor;
else
color = ((color-1) % andcolor) + 1; /* skip color zero */
(*plot)(col,row,color);
if(numpasses && (passes == 0))
(*plot)(col,row+1,color);
}
}
startrow = passes + 1;
}
testend();
return(0);
}
/***************** standalone engine for "plasma" ********************/
static int iparmx; /* iparmx = parm.x * 16 */
static int shiftvalue; /* shift based on #colors */
extern int max_colors;
static int recur1=1;
static int pcolors;
static int recur_level = 0;
U16 max_plasma;
/* returns a random 16 bit value that is never 0 */
U16 rand16()
{
U16 value;
value = rand15();
value <<= 1;
value += rand15()&1;
if(value < 1)
value = 1;
return(value);
}
void _fastcall putpot(int x, int y, U16 color)
{
if(color < 1)
color = 1;
putcolor(x, y, color >> 8 ? color >> 8 : 1); /* don't write 0 */
/* we don't write this if dotmode==11 because the above putcolor
was already a "writedisk" in that case */
if (dotmode != 11)
writedisk(x+sxoffs,y+syoffs,color >> 8); /* upper 8 bits */
writedisk(x+sxoffs,y+sydots+syoffs,color&255); /* lower 8 bits */
}
U16 _fastcall getpot(int x, int y)
{
U16 color;
color = (U16)readdisk(x+sxoffs,y+syoffs);
color = (color << 8) + (U16) readdisk(x+sxoffs,y+sydots+syoffs);
return(color);
}
typedef struct palett
{
BYTE red;
BYTE green;
BYTE blue;
}
Palettetype;
extern Palettetype dacbox[256];
static int plasma_check; /* to limit kbd checking */
static U16 _fastcall adjust(int xa,int ya,int x,int y,int xb,int yb)
{
S32 pseudorandom;
pseudorandom = ((S32)iparmx)*((rand15()-16383));
/* pseudorandom = pseudorandom*(abs(xa-xb)+abs(ya-yb));*/
pseudorandom = pseudorandom * recur1;
pseudorandom = pseudorandom >> shiftvalue;
pseudorandom = (((S32)getpix(xa,ya)+(S32)getpix(xb,yb)+1)>>1)+pseudorandom;
if(max_plasma == 0)
{
if (pseudorandom >= pcolors)
pseudorandom = pcolors-1;
}
else if (pseudorandom >= max_plasma)
pseudorandom = max_plasma;
if(pseudorandom < 1)
pseudorandom = 1;
plot(x,y,(U16)pseudorandom);
return((U16)pseudorandom);
}
static int _fastcall new_subD (int x1,int y1,int x2,int y2, int recur)
{
int x,y;
int nx1;
int nx;
int ny1, ny;
S32 i, v;
struct sub {
BYTE t; /* top of stack */
int v[16]; /* subdivided value */
BYTE r[16]; /* recursion level */
};
static struct sub subx, suby;
/*
recur1=1;
for (i=1;i<=recur;i++)
recur1 = recur1 * 2;
recur1=320/recur1;
*/
recur1 = 320L >> recur;
suby.t = 2;
ny = suby.v[0] = y2;
ny1 = suby.v[2] = y1;
suby.r[0] = suby.r[2] = 0;
suby.r[1] = 1;
y = suby.v[1] = (ny1 + ny) >> 1;
while (suby.t >= 1)
{
if ((++plasma_check & 0x0f) == 1)
if(check_key())
{
/* naah, we don't want to flush this key!!!
getch();
*/
plasma_check--;
return(1);
}
while (suby.r[suby.t-1] < recur)
{
/* 1. Create new entry at top of the stack */
/* 2. Copy old top value to new top value. */
/* This is largest y value. */
/* 3. Smallest y is now old mid point */
/* 4. Set new mid point recursion level */
/* 5. New mid point value is average */
/* of largest and smallest */
suby.t++;
ny1 = suby.v[suby.t] = suby.v[suby.t-1];
ny = suby.v[suby.t-2];
suby.r[suby.t] = suby.r[suby.t-1];
y = suby.v[suby.t-1] = (ny1 + ny) >> 1;
suby.r[suby.t-1] = (int)max(suby.r[suby.t], suby.r[suby.t-2])+1;
}
subx.t = 2;
nx = subx.v[0] = x2;
nx1 = subx.v[2] = x1;
subx.r[0] = subx.r[2] = 0;
subx.r[1] = 1;
x = subx.v[1] = (nx1 + nx) >> 1;
while (subx.t >= 1)
{
while (subx.r[subx.t-1] < recur)
{
subx.t++; /* move the top ofthe stack up 1 */
nx1 = subx.v[subx.t] = subx.v[subx.t-1];
nx = subx.v[subx.t-2];
subx.r[subx.t] = subx.r[subx.t-1];
x = subx.v[subx.t-1] = (nx1 + nx) >> 1;
subx.r[subx.t-1] = (int)max(subx.r[subx.t],
subx.r[subx.t-2])+1;
}
if ((i = getpix(nx, y)) == 0)
i = adjust(nx,ny1,nx,y ,nx,ny);
v = i;
if ((i = getpix(x, ny